// 存储数据信息
export const state = () => {
    return {
        userInfo: {
            token: '',
            user: {}
        }
    }
}
// 修改数据
export const mutations = {
    setUserInfo(state, data) {
        state.userInfo = data
    }
}
// 执行异步操作
export const actions = {
    login(store, data) {
        return this.$axios({
            url: "/accounts/login",
            method: "post",
            data
        }).then(res => {
            // console.log(res.data);
            //登录成功之后将数据store存储
            store.commit("setUserInfo", res.data);
            // console.log(this.$store.state.user.userInfo);
            return res
        });
    },
    register(store, data) {
        return this.$axios({
            url: "/accounts/register",
            method: "post",
            data
        }).then(res => {
            return res
        })
    }
}